// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

// This test case verifies that the listview updates its layout / geometry when the
// entire model changes. This test works by triggering layout updates by simulating
// mouse clicks, which results in item tree traversal and ensure_updated_listview
// calls, similar to when painting. The actual model change is triggered via simulated
// mouse clicks into the touch area further down.
// Note: The C++ test uses the same test method, but due to its differing implementation
// it's not testing the same code path.

import { ListView } from "std-widgets.slint";

TestCase := Window {
    width: 300px;
    height: 300px;

    property<length> viewport-height: lv.viewport-height;
    property<[length]> fixed-height-model: [100px, 0px];

    lv := ListView {
        for fixed-height in fixed-height-model: Rectangle {
            background: blue;
            height: fixed-height;
        }
    }

    TouchArea {
        y: 50px;
        clicked => {
            fixed-height-model = [200px];
        }
    }
}


/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;

// Send an initial click to traverse the item tree and force a listview
// layout.
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_viewport_height(), 100.);

// Trigger the mouse area to change the model
slint_testing::send_mouse_click(&instance, 5., 55.);

// Send a second click to force an item tree traversal and listview update
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_viewport_height(), 200.);
```


```rust
let instance = TestCase::new().unwrap();

// Send an initial click to traverse the item tree and force a listview
// layout.
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_viewport_height(), 100.);

// Trigger the mouse area to change the model
slint_testing::send_mouse_click(&instance, 5., 55.);

// Send a second click to force an item tree traversal and listview update
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_viewport_height(), 200.);
```

```js
var instance = new slint.TestCase();

// Send an initial click to traverse the item tree and force a listview
// layout.
instance.send_mouse_click(5., 5.);
assert.equal(instance.viewport_height, 100.);

// Trigger the mouse area to change the model
instance.send_mouse_click(5., 55.);

// Send a second click to force an item tree traversal and listview update
instance.send_mouse_click(5., 5.);
assert.equal(instance.viewport_height, 200.);
```
*/
